import { messages } from "share/common";
import React from "react";
import moment from "moment";
import Condition from "components/condition";
import { Button } from "antd";

const { If } = Condition;

export default function VendorCard(props) {
  const { vendor = {}, book, index, businessCode } = props;
  const { supplierIcon, supplierName, syncState, syncTime, loading } = vendor;
  return (
    <div
      className={[syncState ? "success-v" : "error-v", "vendor-card"].join(" ")}
      onClick={() => {
        book(vendor);
      }}
    >
      <If value={syncState && syncTime}>
        <div className="sync-date">
          {
            messages("request-1.key886", {
              arg1: businessCode,
              arg2: moment(syncTime).format("YYYY-MM-DDHH:mm"),
            }) /*审批单{arg1}于{arg2}同步成功*/
          }
        </div>
      </If>
      <div className="vendor-info">
        <div className="vendor-info-l">
          <img className="vendor-icon" src={supplierIcon} alt="icon" />
          <div className="vendor-name">{supplierName}</div>
        </div>
        <If value={syncState}>
          <div className="vendor-info-r">
            <Button loading={loading} type="primary" className="btn-book" ghost>
              {messages("request-1.key887") /*预定*/}
            </Button>
          </div>
        </If>
      </div>
    </div>
  );
}
